package com.link2room.soundwave.nmsrunner;

import com.aliyun.mns.model.Message;
import com.link2room.common.enums.BaseSysExceptionEnum;
import com.link2room.common.mns.Worker;
import com.link2room.common.util.BatchUtil;
import com.link2room.common.util.ExceptionUtil;
import com.link2room.common.util.JacksonUtil;
import com.link2room.common.util.LogUtil;
import com.link2room.soundwave.dto.param.base.PmsReservationBaseParamDto;
import com.link2room.soundwave.util.HandlerUtil;
import org.springframework.stereotype.Component;

/**
 * Created by sss on 2016/9/21.
 */
@Component("pmsReservationStaRunner")
public class PMSReservationStaRunnerImpl implements Worker {


    @Override
    public boolean exec(Message message) throws Exception {
        try{
            PmsReservationBaseParamDto pmsBookInfoParamDto = JacksonUtil.jsonToBean(message.getMessageBody(), PmsReservationBaseParamDto.class);
            if(message.getDequeueCount()==1){
                HandlerUtil.pmsReservationHandler().syncPMSHotelReservationStaHandler(pmsBookInfoParamDto);
            }else {
                BatchUtil.doBatchTaskFail(pmsBookInfoParamDto.getTaskMainId(),pmsBookInfoParamDto.getTaskId(), BaseSysExceptionEnum.MNS_COUNT_ABOVE.getMsg());
            }
        }catch (Exception e){
            String errorDetail= ExceptionUtil.getExceptionDetail(e);
            LogUtil.logger.error(errorDetail);
            return false;
        }finally {
            return true;
        }
    }
}
